<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 组合继承：属性在构造函数内部继承，方法通过原型继承
    function Person(name,age) {
      this.name = name;
      this.age = age;
    }
    Person.prototype.sayHi = function () {
      console.log("你好");
    }
    // 生成一个子类型
    function Teacher(name,age,salary) {
      // 继承父类的属性
      Person.call(this,name,age);
      this.salary = salary;
    }
    // 方法继承，通过原型对象继承
    Teacher.prototype = new Person();
    Teacher.prototype.constructor = Teacher;
    // 生成老师的一个实例
    var t1 = new Teacher("wang",45,10000);
    console.dir(t1);
    console.log(t1.name);
    t1.sayHi();
  </script>
</body>
</html>